//
// Created by Administrator on 2021/10/20.
//
#include <iostream>
#include <set>
#include <map>
#include <cmath>

using namespace std;


int clusters(const multiset<int>& test) {
    if (test.empty())
    {
        return 0;
    }
    else
    {
        set<int> test2;
        set<int>::iterator it;
        int num = 0;
        for (it = test.begin(); it != test.end(); it++)
        {
            test2.insert(*it);
        }
        for (it = test2.begin(); it != test2.end(); it++)
        {
            if (test.count(*it) > 1)
            {
                num++;
            }
        }
        test2.clear();
        return num;
    }
}

bool sameKeyValue(const multimap<int, int>& test) {
    multimap<int, int>::const_iterator it;
    for (it = test.begin(); it != test.end(); it++)
    {
        if (test.find(it->second) == test.end())
        {
            return false;
        }
    }
    return true;
}

void tenMultiplesOf(set<int>& result, const int value) {
    int index = 2;
    while (result.size() < 10)
    {
        if (value * index % 10 != value)
        {
            result.insert(value * index);
        }
        index++;
    }
}

int main() {
    std::cout << "Hello, World!" << std::endl;
    multiset<int> test;
    test.insert(1);
    test.insert(2);
    test.insert(2);
    test.insert(3);
    test.insert(4);
    test.insert(4);
    cout << clusters(test) << endl;

    multimap<int, int> test2 {{3, 3,}, {4, 4}, {5, 1}, {6, 2}, {7, 3}, {7, 5}};
    multimap<int, int> test3 {{1, 2,}, {2, 6}, {4, 2}, {4, 6}, {6, 4}};
    cout << ((sameKeyValue(test2)) ? " => true\n" : " => false\n" );
    cout << ((sameKeyValue(test3)) ? " => true\n" : " => false\n" );

    set<int> result;
    tenMultiplesOf(result, 2);
    set<int>::iterator it;
    for (it = result.begin(); it != result.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
    result.clear();
    tenMultiplesOf(result, 3);
    for (it = result.begin(); it != result.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}

